package com.cn.xiaonuo.common.entity;

import io.swagger.annotations.ApiModelProperty;
import org.springframework.stereotype.Repository;


/**
 * 通用业务消息类
 *
 * @param <T> 实体
 */
@Repository
public class BusinessMessage<T> {

    /**
     * 业务执行结果
     */
    @ApiModelProperty(value = "成功标识；true：成功；false:失败")
    public Boolean success = false;

    /**
     * 业务代码
     */
    @ApiModelProperty(value = "返回状态码；200:成功")
    public String code = "";

    /**
     * 业务消息
     */
    @ApiModelProperty(value = "描述信息")
    public String message = "";

    /**
     * 业务数据
     */
    public T data;
    private Integer pageSize;
    private Integer pageNum;
    private Integer dataTol;

    private static final String SUCCESS_CODE = "200";

    private static final String SUCCESS_MESSAGE = "操作成功";

    private static final String FAIL_MESSAGE = "操作失败";

    private static final String FAIL_CODE = "-1";

    public BusinessMessage(Boolean success, String code, T t) {
        this.success = success;
        this.code = code;
        this.data = t;
        this.message = SUCCESS_MESSAGE;
    }

    public BusinessMessage(Boolean success, String code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public BusinessMessage() {
    }

    public static BusinessMessage success(Object data) {
        return new BusinessMessage(true, SUCCESS_CODE, data);
    }

    public static BusinessMessage success() {
        return success(null);
    }

    public static BusinessMessage fail(String message) {
        return new BusinessMessage(false, FAIL_CODE, message);
    }

    public static BusinessMessage fail() {
        return fail(FAIL_MESSAGE);
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getDataTol() {
        return dataTol;
    }

    public void setDataTol(Integer dataTol) {
        this.dataTol = dataTol;
    }
}
